using UnityEngine;

namespace Crosstales.UI.Audio
{
    // [Assembly-CSharp-firstpass.dll].Crosstales.UI.Audio.AudioSourceController
    public class AudioSourceController : MonoBehaviour
    {
        // Fields
        public bool FindAllAudioSourcesOnStart;
        public UnityEngine.AudioSource[] AudioSources;
        public bool ResetAudioSourcesOnStart;
        public bool Mute;
        public bool Loop;
        public float Volume;
        public float Pitch;
        public float StereoPan;
        public UnityEngine.UI.Text VolumeText;
        public UnityEngine.UI.Text PitchText;
        public UnityEngine.UI.Text StereoPanText;
        private bool initialized;
        
        // Methods
        private void Update()
        {
            if(this.initialized == true)
            {
                    return;
            }
            
            int val_1 = UnityEngine.Time.frameCount;
            var val_3 = 0;
            val_3 = val_3 + val_1;
            val_3 = (val_3 >> 4) + (val_3 >> 31);
            val_3 = val_1 - (val_3 * 30);
            if(val_3 != 0)
            {
                    return;
            }
            
            this.initialized = true;
            if(this.FindAllAudioSourcesOnStart != false)
            {
                    this.FindAllAudioSources();
            }
            
            if(this.ResetAudioSourcesOnStart == false)
            {
                    return;
            }
            
            this.ResetAllAudioSources();
        }
        public void FindAllAudioSources()
        {
            Unknown val_2 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753697}));
            this.AudioSources = null;
        }
        public void ResetAllAudioSources()
        {
            this.MuteEnabled(isEnabled:  this.Mute);
            this.LoopEnabled(isEnabled:  this.Loop);
            this.VolumeChanged(value:  this.Volume);
            this.PitchChanged(value:  this.Pitch);
            this.StereoPanChanged(value:  this.StereoPan);
        }
        public void MuteEnabled(bool isEnabled)
        {
            if(this.AudioSources.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.AudioSources.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.AudioSources[val_3].mute = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.AudioSources.Length);
        
        }
        public void LoopEnabled(bool isEnabled)
        {
            if(this.AudioSources.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.AudioSources.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.AudioSources[val_3].mute = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.AudioSources.Length);
        
        }
        public void VolumeChanged(float value)
        {
            if(this.AudioSources.Length >= 1)
            {
                    var val_4 = 0;
                do
            {
                if(val_4 >= this.AudioSources.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.AudioSources[val_4].volume = value;
                val_4 = val_4 + 1;
            }
            while(val_4 < this.AudioSources.Length);
            
            }
            
            if(this.VolumeText == 0)
            {
                    return;
            }
            
            string val_2 = value.ToString(format:  -1610611397);
        }
        public void PitchChanged(float value)
        {
            if(this.AudioSources.Length >= 1)
            {
                    var val_4 = 0;
                do
            {
                if(val_4 >= this.AudioSources.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.AudioSources[val_4].pitch = value;
                val_4 = val_4 + 1;
            }
            while(val_4 < this.AudioSources.Length);
            
            }
            
            if(this.PitchText == 0)
            {
                    return;
            }
            
            string val_2 = value.ToString(format:  -1610611397);
        }
        public void StereoPanChanged(float value)
        {
            if(this.AudioSources.Length >= 1)
            {
                    var val_4 = 0;
                do
            {
                if(val_4 >= this.AudioSources.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.AudioSources[val_4].panStereo = value;
                val_4 = val_4 + 1;
            }
            while(val_4 < this.AudioSources.Length);
            
            }
            
            if(this.StereoPanText == 0)
            {
                    return;
            }
            
            string val_2 = value.ToString(format:  -1610611397);
        }
        public AudioSourceController()
        {
            this.FindAllAudioSourcesOnStart = true;
            this.ResetAudioSourcesOnStart = true;
            this.Volume = 1;
        }
    
    }

}
